import { alertTwoButt, platform, settingPrivacy } from "../base";
import yhTools from "../../tools/yh";

/**
 * 选择图片方法
 *
 * @param {*} objs
 *
 * objs
 *
 * -type            选择类型
 * -imageName       图片名称
 * -imageSize       图片大小（压缩目标值）
 * -thumbnailSize   图片缩略图大小
 */
export function imagePicker(objs) {
	if (yhTools.platform() === "web") {
		return new Promise(function (resolve) {
			let resp = {
				status: "1000",
				data: {
					path: "/user/data/saveAdress", //图片路径
					base64:
						"" //缩略图，图片base64编码
				}
			};
			resolve(resp);
		});
	} else {
		return new Promise(function (resolve, reject) {
			window.YHAuthorize.callHandler("Privacy_ImagePicker", objs, resp => {
				if (resp.status == "1000") {
					resolve(resp);
				} else {
					reject(resp);
					if (resp.status == "3001") {
						// 权限相关
						let showMsg = "";
						if (platform() == "ios") {
							showMsg = `本应用暂时无法访问相机，请进入“设置-隐私-相机”进行授权。`;
						} else {
							showMsg = `暂时无法打开相机，请进入权限管理中授信本应用读取存储文件或照片。`;
						}
						alertTwoButt(showMsg, "去设置", "取消", () => {
							settingPrivacy();
						});
					}
				}
			});
		});
	}
}

export function getLocation() {
	if (yhTools.platform() === "web") {
		return new Promise(function (resolve) {
			let resp = {
				status: "1000",
				data: {
					latitude: "", //纬度
					longitude: "" //经度
				}
			};
			resolve(resp);
		});
	} else {
		return new Promise(function (resolve) {
			window.YHAuthorize.callHandler("Privacy_Loaction", "", resp => {
				if (resp.status == "1000") {
					resolve(resp);
				} else {
					let res = {
						status: "1000",
						data: {
							latitude: "", //纬度
							longitude: "" //经度
						}
					};
					resolve(res);
				}
			});
		});
	}
}
/**
 * 显示华通键盘
 * @param {*} objs
 * * objs
 *
 * -isShow        是否显示键盘(0:关闭 1:显示)
 */
export function showHTkeyboard(objs) {
	if (yhTools.platform() === "web") {
		return new Promise(function (resolve) {
			let resp = {
				status: "1000",
				data: {}
			};
			resolve(resp);
		});
	} else {
		return new Promise(function (resolve) {
			window.YHAuthorize.callHandler("SHOW_HT_KEYBOARD", objs, resp => {
				if (resp.status == "1000") {
					resolve(resp);
				} else {
					let res = {
						status: "2000",
						data: {}
					};
					resolve(res);
				}
			});
		});
	}
}
